package view;

import java.awt.*;
import javax.swing.*;

import controller.*;
import model.*;
import java.awt.event.*;
import java.util.ArrayList;

public class froggerView extends JFrame {
    
	private static final long serialVersionUID = 7632650284490142197L;
	
	private gameModelI model;
    
    class gamePanel extends JPanel implements KeyListener {
		/**
		 * 
		 */
		private static final long serialVersionUID = -7820991932017770969L;
		private userInputHandler userinput;

		public gamePanel() {
			setBackground(Color.white);
			setLayout(new FlowLayout());
			setPreferredSize(new Dimension(1000, 600));	
			//userinput = new userInputHandler();
		}
	
	    public void paint(Graphics g) {
	    	super.paintComponent(g);
	    	g.setColor(Color.black);
	    	ArrayList<log> list = model.getLogs();
	    	frog gameFrog = model.getFrog();
	    	for (int i = 0; i < list.size(); i++) {
	    		g.drawRect(list.get(i).getPosX(), list.get(i).getPosY(), list.get(i).getWidth(), list.get(i).getHeight());
	            g.drawString(list.get(i).getWord(), list.get(i).getPosX()+20, list.get(i).getPosY()+20);	        
	    	}
	    	g.setColor(Color.green);
	    	g.fillOval(gameFrog.getPosX(), gameFrog.getPosY(), 40, 40);
	    }

		@Override
		public void keyPressed(KeyEvent keyinput) {
			userinput.processInput(keyinput.getKeyChar());			
		}
		
		@Override
		public void keyReleased(KeyEvent key) {						
		}
		
		@Override
		public void keyTyped(KeyEvent arg0) {}
    }
    
    public froggerView(gameModelI model) {
    	super("Frogger Test - MVC");
        this.model = model;        
             
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLayout(new BorderLayout());
		setSize(1000, 600);
		
		//create the gamePanel
		JPanel game = new gamePanel();
		setContentPane(game);		
		pack();
		setVisible(true);
		
		// Must do this to see KeyEvents.
		game.setFocusable(true);
    }
    

    
    
 // WE NEED ACTION LISTENERS THAT SEND MESSAGES TO A CONTROLLER INTERFACE


}